import { createStore } from 'vuex'

// 从localStorage获取保存的皮肤设置
const getSavedSkin = () => {
  const saved = localStorage.getItem('skin-setting')
  if (saved) {
    return JSON.parse(saved)
  }
  return {
    img: new URL('@/assets/my/banner.png', import.meta.url).href,
    bgColor: '#fb8fae'
  }
}

export default createStore({
  state: {
    skin: getSavedSkin()
  },
  getters: {
  },
  mutations: {
    setSkin(state, payload) {
      state.skin.img = payload.img;
      state.skin.bgColor = payload.bgColor;
      
      // 保存到localStorage
      localStorage.setItem('skin-setting', JSON.stringify(state.skin))
    }
  },
  actions: {
  },
  modules: {
  }
})